#ifndef DW_COMMAND_LINE_INL
#	define DW_COMMAND_LINE_INL

#include "system/commandline.h"

#include <algorithm>

#include "base/stringutils.h"

namespace dw {
	namespace system {

template< typename T >
void CommandLine::RegisterParameter(const std::string& name, const T& defaultValue)
{
	std::string nameUpper;

	nameUpper.resize(name.size());
	std::transform(name.begin(), name.end(), nameUpper.begin(), ::toupper);

	dwAssert(_parameters.find(nameUpper) == _parameters.end(), "Invalid parameter: name");

	Parameter< T >* parameter = new Parameter< T >(defaultValue);

	_parameters[nameUpper] = parameter;
}


template< typename T >
T CommandLine::GetParameterValue(const std::string& name)
{
	std::string nameUpper;

	nameUpper.resize(name.size());
	std::transform(name.begin(), name.end(), nameUpper.begin(), ::toupper);

	dwAssert(_parameters.find(nameUpper) != _parameters.end(), "Invalid parameter: name");

	return static_cast< Parameter< T >* >(_parameters[nameUpper])->GetValue();
}

template< typename T >
void CommandLine::Parameter< T >::SetValueFromString(const std::string& str)
{
	fromString< T >(str, _value);
}

template< typename T >
std::string CommandLine::Parameter< T >::GetValueToString() const
{
	std::string outputStr;

	if (toString< T >(_value, outputStr))
	{
		return outputStr;
	}

	return "invalid";
}

	} // namespace system
} // namespace dw

#endif // !DW_COMMAND_LINE_INL
